package com.cqupt.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cqupt.model.pojo.WordAcc;
import com.cqupt.service.WordAccService;
import com.cqupt.mapper.WordAccMapper;
import com.cqupt.utils.AuthContextUtil;
import jakarta.annotation.Resource;
import org.apache.http.auth.AUTH;
import org.springframework.stereotype.Service;


@Service
public class WordAccServiceImpl extends ServiceImpl<WordAccMapper, WordAcc>
        implements WordAccService {

    @Resource
    private WordAccMapper wordAccMapper;

    @Override
    public Integer getAcc() {
        Integer userId = AuthContextUtil.get().getId();
        LambdaQueryWrapper<WordAcc> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WordAcc::getUserId, userId);
        WordAcc wordAcc = wordAccMapper.selectOne(wrapper);
        if (ObjectUtil.isNull(wordAcc)) {
            return 0;
        }
        Integer rightCount = wordAcc.getRightCount();
        Integer totalCount = wordAcc.getTotalCount();
        int acc = rightCount * 100 / totalCount;
        return acc;
    }
}




